//
//  GYStatusOriginalView.swift
//  Weibo
//
//  Created by vane on 16/8/13.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
import SnapKit
class GYStatusOriginalView: UIView {
    
    var originalViewBottomConstraint: Constraint?
    
    var statusViewModel: GYStatusViewModel?{
        didSet{
            headImageView.gy_setImageWithString(statusViewModel?.statusModel?.user?.profile_image_url, placeholderImgName: "avatar_default")
            nameLabel.text = statusViewModel?.statusModel?.user?.name
            timeLabel.text = statusViewModel?.sinaTimeStr

            sourceLabel.text = statusViewModel?.sinaSourceStr
            contentLabel.text = statusViewModel?.statusModel?.text
            membershipImageView.image = statusViewModel?.mbrankImage
            avatarImageView.image = statusViewModel?.verifiedImage
            
            
            
            originalViewBottomConstraint?.uninstall()

            if statusViewModel?.statusModel?.pic_urls?.count > 0 {
                
                pictureView.pictureInfos = statusViewModel?.statusModel?.pic_urls
              
                self.snp_makeConstraints { (make) -> Void in
                    originalViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                }
          
                pictureView.hidden = false
            }else {
            
                self.snp_makeConstraints { (make) -> Void in
                    originalViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                }
          
                pictureView.hidden = true
            }
        }
    }
       
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
        backgroundColor = UIColor.whiteColor()
        
        addSubview(headImageView)
        addSubview(nameLabel)
        addSubview(membershipImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(avatarImageView)
        addSubview(contentLabel)
        addSubview(pictureView)
        
        headImageView.snp_makeConstraints { (make) -> Void in
            
            make.leading.top.equalTo(10)
            make.size.equalTo(CGSize.init(width: 35, height: 35))
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(headImageView.snp_trailing).offset(10)
            make.top.equalTo(headImageView)
        }
        
        membershipImageView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(nameLabel.snp_trailing).offset(10)
            make.centerY.equalTo(nameLabel)
        }
        
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(nameLabel)
            make.bottom.equalTo(headImageView)
        }
       
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(timeLabel.snp_trailing).offset(10)
            make.bottom.equalTo(timeLabel)
        }
        
        avatarImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView.snp_trailing)
            make.centerY.equalTo(headImageView.snp_bottom)
            
        }
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImageView.snp_bottom).offset(10)
            make.leading.equalTo(10)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
            make.leading.equalTo((SCREENW - 250)/2)
//            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        
        self.snp_makeConstraints { (make) -> Void in
           originalViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }



    }
    private lazy var headImageView:UIImageView = UIImageView(imgName: "avatar_default")
    
    private lazy var nameLabel:UILabel = UILabel(textColor: UIColor.darkGrayColor(), textSize: 15)
    
    private lazy var membershipImageView: UIImageView = UIImageView(imgName: "common_icon_membership")
   
    private lazy var timeLabel: UILabel = UILabel(textColor: AppThemeColor, textSize: 10)
    
    private lazy var sourceLabel: UILabel = UILabel(textColor: UIColor.grayColor(), textSize: 10)
    
    private lazy var avatarImageView: UIImageView = UIImageView(imgName: "avatar_vgirl")
    
     private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.blackColor(), textSize: 15, maxWidth: SCREENW - 20)
    
    private lazy var pictureView:GYStatusPictureView = GYStatusPictureView()
}
